Dynomotion

Group: DynoMotion Message: 9521 From: Toby Rule Date: 5/23/2014
Subject: console data getting mangled

Hi Tom,

 

I am collecting some data in a buffer on the DSP which consists of X,Y,Z points combined with an analog measurement, and then transmitting the data points to the PC using printf statements.  The printf statement looks something like:

 

printf(“MyData %3.3f %3.3f %3.3f %3.3f\n”,data1, data2, data3, data4);

 

Then on the PC I watch the console output for the MyData tag and parse the output lines.

 

However, it seems like these MyData lines are getting mangled under certain conditions.  The characters are not coming through in the correct order, or else some other console data is being intermingled with these lines. 

 

Does the printf statement get split across time-slices, so that the data gets loaded into the console buffer in different slices?  Do I need to do a WaitNextTimeSlice() before printf, or use shorter strings If I want them to get transmitted in one piece?

 

Thanks,

 

Toby

 


The information contained in this transmission is intended only for the person or entity
to which it is addressed and may contain II-VI Proprietary and/or II-VI Business Sensitive
material. If you are not the intended recipient, please contact the sender immediately
and destroy the material in its entirety, whether electronic or hard copy. You are
notified that any review, retransmission, copying, disclosure, dissemination or other
use of, or taking of any action in reliance upon this information by persons or entities
other than the intended recipient is prohibited.
Group: DynoMotion Message: 9523 From: Tom Kerekes Date: 5/23/2014
Subject: Re: console data getting mangled
Hi Toby,

Are you printing to the Console from multiple Threads? 

Probably a better method to upload data would be to but the data into the Gather Buffer and then upload it with the GetGatherHex command.

printf is intended more as a diagnostic command.  But I suppose it should work.

A printf is a relatively expensive complex command involving a lot of double precision floating point math as well as the USB communication.  It could easily take a millisecond or more (many time slices).  A WaitforNextTimeSlice() only provides a few microseconds of guaranteed uniterrupted execution.

You might try putting an additional Mutex around all your Threads accesses to printf (there are already some internal Mutex locks).  KMotionDef.h defines these functions.

// used to allow mutual exclusive access to a resource
// (waits until resource is available, then locks it)
// if the thread that locked it is no longer active,
// release the lock

void MutexLock(int *mutex);
void MutexUnlock(int *mutex);

You must define a global mutex.  Which is simply an integer variable used as a flag.  You could use a persist.UserData[xx] variable.

So then if one of your Threads already called MutexLock and another Thread tried to obtain the lock it would block until the first Thread released the lock.

HTH
Regards
TK




Group: DynoMotion Message: 9557 From: Toby Rule Date: 5/27/2014
Subject: Re: console data getting mangled

Hi Tom,

 

It looks like putting the data in the Gather buffer is the best solution – it will be faster and more reliable. 

 

Thanks,

 

Toby